package DataStructure.Tree.binaryTree;

/**
 * @Author: Dijah
 * @Date: 2023/8/8 17:37
 * @Desc: 定义二叉树
 */
public class TreeModel {

    private int no;

    private String name;

    private TreeModel left;//默认为null

    private TreeModel right;//默认为null

    public TreeModel(int no,String name){
        this.no = no;
        this.name = name;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public TreeModel getLeft() {
        return left;
    }

    public void setLeft(TreeModel left) {
        this.left = left;
    }

    public TreeModel getRight() {
        return right;
    }

    public void setRight(TreeModel right) {
        this.right = right;
    }

    @Override
    public String toString() {
        return "TreeModel{" +
                "no=" + no +
                ", name='" + name + '\'' +
                ", left=" + left +
                ", right=" + right +
                '}';
    }

    //DLR=前序遍历
    public void dLRTree(){
        System.out.println(this);
        //递归左子树
        if(this.left != null){
            this.left.dLRTree();
        }
        //递归右子树
        if(this.right != null){
            this.right.dLRTree();
        }
    }

    //LDR=中序遍历
    public void lDRTree(){
        if(this.left != null){
            this.left.lDRTree();
        }
        System.out.println(this);
        //递归右子树
        if(this.right != null){
            this.right.lDRTree();
        }
    }

    //LRD=后续遍历
    public void lRDTree(){
        if(this.left != null){
            this.left.lRDTree();
        }
        if(this.right != null){
            this.right.lRDTree();
        }
        System.out.println(this );
    }
}
